#pragma once
#include "stdafx.h"

/// DOXYS_OFF
#define VALUECHUNK 16	// Value chunk to be used for memory allocation.
/// DOXYS_ON

using namespace std;

/** DO Class: Used for representing ISO-7816 Data Objects.
This class introduces object Oriented behaviour in Data Objects(DO), which are basic data units of Smart card.
The format of DO is "Tag-Length-Value", in short TLV. Here value of the "Length" field is length of "Value" field.
- "Tag" can be of  one byte or two byte.
- The value of "Length" field can be of either one byte or two byte.
- "Length" must contain the exact number of bytes in "Value" field.
*/
class DO 
{
protected:
	WORD tag;		///< One-byte or two-byte tag for the DO.
	WORD length;	///< Length of the DO. A number between 0 to 65535.
	BYTE *value;	///< Value field of the DO.        
	
public:
	DO(void);
	~DO(void);	
	DO(WORD tag_arg);
	DO(const BYTE tag_arg[], WORD length_arg, const BYTE *value_arg);
	DO(WORD tag_arg, WORD length_arg, const BYTE *value_arg);
	DO(WORD tag_arg, BYTE value_arg);
	DO(const DO &do_arg);
	DO(const BYTE *byte_stream);

	void setTag(const BYTE *tag_arg);
	void setTag(const WORD tag_arg);
	void setValue(WORD length_arg, const BYTE *value_arg);
	void setConstructedValue(const list<DO>& collection);
	
	WORD getTag(void) const;
	WORD getLength() const;
	BYTE* getValue(void) const;
	WORD getTotalBytes(BYTE *buffer) const;
	WORD getTotalLength(void) const;

	DO& operator+(const BYTE vchar);
	WORD appendValue(WORD length_arg, const BYTE *buffer);
	void appendDO(const DO& do_arg);
	void appendDO(WORD tag_arg, WORD length_arg, const BYTE *value_arg);
};

list<DO> getList(int length, const BYTE* byte_stream);
